<?php

namespace app\index\controller;

use app\index\model\PcSoftInfo;
use think\Controller;
use think\Db;
use think\Env;
use think\Request;

class Download extends Controller
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {

//        dump($this->request->get('type'));die;
        $soft_id = $_GET['type'];
//        dump($_GET);die;
        $cate_list_6 = Db::name('category_soft')->limit(6)->select();
        $soft_info = PcSoftInfo::find($soft_id);

        //jingpintuijian
        $where['Status']    = ['=',PcSoftInfo::STATUS_1];
        $recommend_list = Db::name('pc_soft_info')
            ->where($where)
            ->where('IsRecommend','=',1)
            ->order('OrderBy','DESC')
            ->limit(0,6)
            ->select();
        $good_ping_list = Db::name('pc_soft_info')
            ->where($where)
            ->where('good_evaluation','=',1)
            ->order('OrderBy','DESC')
            ->limit(0,8)
            ->select();

        $host_search_list_6 = Db::name('pc_soft_info')
            ->where($where)
            ->where('hot_search','=',1)
            ->order('OrderBy','DESC')
            ->limit(0,6)
            ->select();

        $host_search_list = Db::name('pc_soft_info')
            ->where($where)
            ->where('hot_search','=',1)
            ->order('OrderBy','DESC')
            ->limit(0,12)
            ->select();

        $good_evaluation_list = Db::name('pc_soft_info')
            ->where($where)
            ->where('good_evaluation','=',1)
            ->order('OrderBy','DESC')
            ->limit(0,12)
            ->select();

        $soft_info['updateDate'] = date('Y-m-d',strtotime($soft_info['updateDate']));
//        $soft_info['Name'] = iconv("utf-8","gb2312",$soft_info['Name']);
//        $soft_info['Detail'] = htmlspecialchars_decode($soft_info['Detail']);

//        dump($soft_info['Name']);die;

        $this->assign('cate_list_6',$cate_list_6);
        $this->assign('soft_info',$soft_info);
        $this->assign('recommend_list',$recommend_list);
        $this->assign('good_ping_list',$good_ping_list);
        $this->assign('host_search_list_6',$host_search_list_6);
        $this->assign('host_search_list',$host_search_list);
        $this->assign('good_evaluation_list',$good_evaluation_list);

        return $this->view->fetch();
    }

    public function index2()
    {
        $request = Request::instance();

        if($request->get('name')){
            $where['Name']      = ['like','%'.$request->get('name').'%'];
        }
        if($request->get('CateId')){
            $category_id      = $request->get('CateId');
            $where['CateId']    = ['=',$category_id];
        }
        $limit            = $request->get('limit','30');
        $where['Status']    = ['=',PcSoftInfo::STATUS_1];
        // 查询分页数据
        $pc_soft_list = Db::name('pc_soft_info')->where($where)->order('id', 'desc')->paginate($limit);

        return json($pc_soft_list);
    }

    public function static_download_count(){
        $params['soft_id'] = $_POST['soft_id'];
        $params['year'] = date('Y');
        $params['month'] = date('m');
        $params['create_time'] = date('Y-m-d H:i:s');

        $res = Db::name('static_soft')->insert($params);
        if($res == 1){
            return $this->success('成功');
        }else{
            //TODO 日志记录--分析原因
            return $this->error('网络异常，请重新尝试！');
        }
        dump(10086);die;
    }





}
